const validate = require("validate.js");
const moment = require('moment');

validate.extend(validate.validators.datetime, {
  // The value is guaranteed not to be null or undefined but otherwise it
  // could be anything.
  parse: function(value, options) {
    return +moment.utc(value);
  },
  // Input is a unix timestamp
  format: function(value, options) {
    var format = "YYYY-MM-DD";
    return moment.utc(value).format(format);
  }
});


const constraints_ActionItem = {
  actionItem: {
    presence: true,
    length: {
      maximum: 50,
      minimum: 5,
    },
  },
  dueDate: {
    presence: true,
    datetime: {
      dateOnly: true,
    },
  },
  status: {
    presence: true,
    inclusion: {
      within: [
        'Open', 
        'Closed',
      ],
      message: "is not valid"
    },
  },
};

const constraints_ActionNote = {
  note: {
    presence: true,
    length: {
      minimum: 5,
    },
  },
  createDate: {
    presence: true,
    datetime: {
      dateOnly: true,
    },
  },
  updateBy: {
    presence:  {
      allowEmpty: false,
    },
  },
};

export {validate, constraints_ActionItem, constraints_ActionNote}